﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Cangku.cy
{
    public partial class TianJia : Form
    {
        public TianJia()
        {
            InitializeComponent();
        }

        private void qued_Click(object sender, EventArgs e)
        {
            string ygxm = this.YGXM.Text.Trim();
            string ygmm = this.YGMM.Text.Trim();
            string ygqx = this.YGQX.Text.Trim();
            if (ygqx=="管理员"||ygqx=="普通用户")
            {
                DBHelper db = new DBHelper();
                string sql = string.Format("insert into [User] select '{0}','{1}','{2}'", ygxm, ygmm, ygqx);
                try
                {
                    bool result = db.ExcuteSql(sql);
                    if (result)
                    {
                        MessageBox.Show("添加成功!");
                        YGXX ower = (YGXX)this.Owner;
                        ower.LoadUser();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("添加失败！");
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("操作失败！请重试！！！");
                    YGXM.Clear();
                    YGMM.Clear();
                    throw;
                }
                
            }
            else
            {
                MessageBox.Show("请输入正确的员工权限！");
            }
            
        }

        private void qux_Click(object sender, EventArgs e)
        {
            YGXM.Clear();
            YGMM.Clear();
            
        }
    }
}
